﻿using System;
using System.ComponentModel;
using System.Data;
using ReflectionStudio.Core.Events;
using System.Windows;
using System.Linq;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for EditEventWindow.xaml
    /// </summary>
    public partial class TGD713AB
    {

        #region ==IsAB===========
        public static readonly DependencyProperty IsABProperty = DependencyProperty.Register("IsAB",
            typeof(bool), typeof(TGD713AB),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsABChanged));
        public bool IsAB
        {
            get
            {
                return (bool)GetValue(IsABProperty);
            }
            set
            {
                SetValue(IsABProperty, value);
            }
        }
        private static void OnIsABChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TGD713AB;
            if (src != null)
            {
                src.IsAB = (bool)e.NewValue;
            }
        }
        #endregion

        #region ==IsGridShow===========
        public static readonly DependencyProperty IsGridShowProperty = DependencyProperty.Register("IsGridShow",
            typeof(bool), typeof(TGD713AB),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsGridShowChanged));
        public bool IsGridShow
        {
            get
            {
                return (bool)GetValue(IsGridShowProperty);
            }
            set
            {
                SetValue(IsGridShowProperty, value);
            }
        }
        private static void OnIsGridShowChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TGD713AB;
            if (src != null)
            {
                src.IsGridShow = (bool)e.NewValue;
            }
        }
        #endregion

        public double QTYEND
        {
            get
            {
                if (dwRule == null)
                    return 1;
                return Convert.ToDouble(dwRule["QTYEND"].ToString());
            }

        }

        public TGD713AB()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VGAAUF();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwGD == null)
            {
                CART = "";
                KEY = "";
                REQ = 0;
                ALLQ = 0;
            }
            else
            {
                REQ = (GAKG1 - GAKG2 - GAKG3 - GAKG5) / 100;
                ALLQ = GAKG3 + GAKG5;
                CART = dwGD["GAART"].ToString() + dwGD["GAVAR"].ToString() + dwGD["GAFARBE"].ToString() + dwGD["GAAUFMSL"].ToString();
                KEY = dwGD["GAAUFKRS"].ToString() + dwGD["GAAUFLFD"].ToString() + dwGD["GAAUFPOS"].ToString() + dwGD["GAPOS"].ToString() + POSTYP;
            }
            if (dwRule == null)
                QTYMAT = 0;
            else
            {
                QTYMAT = Convert.ToDouble(dwRule["QTYMAT"].ToString());
            }
        }


        public override void OnEXAUFChg(string vlaue)
        {
            IsAB = false;
            TBMain.Clear();
            if (vlaue.Length < 11)
                return;
            dwData = TBMain.NewRow();
            dwData["GAMANDANT"] = app.Mandant;
            dwData["GAAUFKRS"] = vlaue.Substring(0, 2);
            dwData["GAAUFLFD"] = vlaue.Substring(2, 6);
            dwData["GAAUFPOS"] = vlaue.Substring(8, 3);  
            dwData["GASA"] = "713";
            SResult = TMV.QGDABAX(dwData);
            if (SResult.Tables[0].Rows.Count > 1)
            {
                IsAB = true;
            }
            vwMaster.Source = SResult.Tables[0];
            //MergeData(SResult, true);
        }

    }
}
